/*
 * Copyright (c) 2018.
 * http://www.ulabcare.com
 */

package com.mt.roll.core.config;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * 参数验证器配置，可以配置验证模式是快速失败返回还是普通模式，开发阶段先开启普通模式
 *
 * @author jiff
 * @date 2018/11/6
 * @since 1.0
 */
@Configuration
public class ValidatorConfig {
    @Bean
    public Validator validator() {
        ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
                .configure()
                //failFast：true 快速失败返回模式，false 普通模式
                .failFast(false)
//                .addProperty("hibernate.validator.fail_fast", "true")
                .buildValidatorFactory();
        Validator validator = validatorFactory.getValidator();

        return validator;
    }

}
